package prv.pursuivant.render.html;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import com.google.inject.internal.Lists;

public class HtmlTableRendererTest {

	@Test
	public void shouldDivide8() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("12345678");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("12345678"));
		assertEquals(expected, result);
	}

	@Test
	public void shouldDivide17() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("12345678901234567");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("12345678901234567"));
		assertEquals(expected, result);
	}

	@Test
	public void shouldDivide32() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("12345678901234567890123456789012");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("1234567890123456"));
		expected.add(makeListFromChars("7890123456789012"));
		assertEquals(expected, result);
	}

	@Test
	public void shouldDivide33() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("123456789012345678901234567890123");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("12345678901234567"));
		expected.add(makeListFromChars("8901234567890123"));
		assertEquals(expected, result);
	}

	@Test
	public void shouldDivide34() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("1234567890123456789012345678901234");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("12345678901234567"));
		expected.add(makeListFromChars("89012345678901234"));
		assertEquals(expected, result);
	}

	@Test
	public void shouldDivide35() {
		HtmlTableRenderer renderer = new HtmlTableRenderer(null, null);
		List<String> ids = makeListFromChars("12345678901234567890123456789012345");
		List<List<String>> result = renderer.divideCrits(ids);
		List<List<String>> expected = Lists.newArrayList();
		expected.add(makeListFromChars("123456789012"));
		expected.add(makeListFromChars("345678901234"));
		expected.add(makeListFromChars("56789012345"));
		assertEquals(expected, result);
	}

	/**
	 * @return
	 */
	private List<String> makeListFromChars(String chars) {
		List<String> result = Lists.newArrayList();
		for (char c : chars.toCharArray())
			result.add("" + c);
		return result;
	}

}
